<?php

// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------


namespace app\index\controller;

use app\index\BaseController;
use Exception;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use think\facade\Request;


/**
 * Class YkcPileTime
 * @package app\index\controller
 * @author xaboy
 */
class YkcPileTime extends BaseController
{
    //定时器执行
    function index(){
        set_time_limit(0);
        $getMin = date("i");
        $getHouse = date("H");
        if($getHouse == 9 && $getMin % 1 == 0){
            Log::info('进入添加虚拟设备和虚拟订单');
            //添加虚拟记录
            try{
                $this->timeAddOrder();
            }catch (Exception $e){
                Log::info($e->getMessage());
            }
            //添加设备
            try{
                $this->timeAddVirtualPile();
            }catch (Exception $e){
                Log::info($e->getMessage());
            }
        }
        //处理记录
        try{
            $this->setOrder();
        }catch (Exception $e){
            Log::info($e->getMessage());
        }

    }

    /*************************  生产虚拟订单  *************************/

    /**
     * 增加虚拟记录
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function timeAddOrder(){
        $pileWhere = ['is_delete'=>1,'is_virtual'=>1,'is_status'=>1];
        $page = 1;
        $limit = 200;
        $status = 1;
        $getDay = date("Y-m-d");
        while ($status){
            $pileList =  Db::table('jy_charge_ykc_pile')->where($pileWhere)->page($page,$limit)
                ->order('id','asc')->select()->toArray();
            $page++;
            if($pileList && !empty($pileList)){
                foreach ($pileList as $key=>$value){
                    $checkData = $this->checkOrderRecord($value,$getDay);
                    //没有记录，增加记录
                    if($checkData['code'] == 0){
                        $recordResult =  Db::table('jy_charge_ykc_virtual_record')->insert($checkData['back_data']);
                        if(!$recordResult) Log::info('设备id为'.$value['id'].'增加虚拟订单失败');
                    }
                }
            }else{
                $status = 0;
                break;
            }
        }
    }

    /**
     * 判断是否当天已经有虚拟记录
     * @param $value
     * @param $getDay
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function checkOrderRecord($value,$getDay,$createTime=0){
        $checkWhere = ['pile_id'=>$value['id'],'date_time'=>$getDay];
        $checkOrderRecord = Db::table('jy_charge_ykc_virtual_record')->where($checkWhere)
            ->where('beg_time','>=',$getDay." 00:00:00")->find();
        if($checkOrderRecord){
            return ['code'=>1,'msg'=>'有对应的记录','back_data'=>$checkOrderRecord];
        }else{
            //$getNowDay = date("Y-m-d");
            $getNowDay = $getDay;
            $begTimeHouse = mt_rand(0,19);
            $begMinSecond = sprintf("%02s",mt_rand(0,59)).":".sprintf("%02s",mt_rand(0,59));
            $endTimeHouse = $begTimeHouse + mt_rand(4,7);
            if($endTimeHouse > 23) $endTimeHouse = 23;
            $endMinSecond = sprintf("%02s",mt_rand(0,59)).":".sprintf("%02s",mt_rand(0,59));
            if(!$createTime) $createTime = date("Y-m-d H:i:s");
            $backData = [
                'is_status'=>0,
                'dz_name'=>$value['dz_name'],
                'code'=>$value['code'],
                'pile_id'=>$value['id'],
                'beg_time'=>$getNowDay." ".sprintf("%02s",$begTimeHouse).":".$begMinSecond,
                'end_time'=>$getNowDay." ".sprintf("%02s",$endTimeHouse).":".$endMinSecond,
                'date_time'=>$getNowDay,
                'order_id'=>0,
                'create_time'=>$createTime,
                'update_time'=>$createTime,
            ];
            return ['code'=>0,'msg'=>'没有对应的记录','back_data'=>$backData];
        }
    }

    /**
     * 订单处理
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function setOrder(){
        $begTime = date("Y-m-d H:i:s",(time()-30 * 24 * 60 * 60));
        $page = 1;
        $limit = 50000;
        $recordList =  Db::table('jy_charge_ykc_virtual_record')
            ->where('is_status','<',100)
            ->where('is_status','>=',0)
            ->where('end_time','<=',date("Y-m-d H:i:s"))
            //->where('beg_time','>',$begTime)
            //->where('pile_id','>=',1700)
            ->order('beg_time','asc')
            ->page($page,$limit)
            ->select()->toArray();
        //dd($recordList);
        if($recordList && !empty($recordList)){
            foreach ($recordList as $key=>$value){
                //当天结束充电小于现在时间的记录
                //if($value['is_status'] == 0 && $value['date_time'] == date("Y-m-d") && strtotime($value['end_time']) <= time()){
                if($value['is_status'] == 0 && strtotime($value['end_time']) <= time()){
                    //获取订单数据
                    $getOrderData = $this->getVirtualOrder($value,date("Y-m-d H:i:s"));
                    if($getOrderData['code'] == 0){
                        Db::startTrans();
                        $orderId = Db::table('jy_charge_ykc_order')->insertGetId($getOrderData['back_data']);
                        if($orderId){
                            $recordData = [
                                'is_status'=>100,
                                'order_id'=>$orderId,
                                'remark'=>'',
                            ];
                            $recordResult = Db::table('jy_charge_ykc_virtual_record')->where('id',$value['id'])->update($recordData);
                            if($recordResult){
                                Db::commit();
                            }else{
                                Db::rollback();
                            }
                        }else{
                            Db::rollback();
                        }
                    }else{
                        Db::table('jy_charge_ykc_virtual_record')->where('id',$value['id'])->update(['remark'=>'获取订单数据失败']);
                    }
                }
            }
        }
    }

    /**
     * 获取虚拟订单数据
     * @param $recordInfo
     * @return array
     */
    function getVirtualOrder($recordInfo,$orderTime){
        if($recordInfo['order_id'] == 0){
            $getCost = $this->countCost($recordInfo);
            $orderTime = date("Y-m-d H:i:s",strtotime($recordInfo['end_time']) + mt_rand(10,80));
            $orderData = [
                'ykc_order'=>$this->getOrderNumber(),
                'charge_terminal'=>$recordInfo['dz_name'],
                'charge_terminal_num'=>$recordInfo['code'],
                'charge_capacity'=>$getCost['all_power'],//充电电量
                'beg_time'=>$recordInfo['beg_time'],
                'end_time'=>$recordInfo['end_time'],
                'order_end_time'=>$orderTime,
                'ele_price'=>$getCost['electric_cost'],//电费
                'servers_price'=>$getCost['service_cost'],//服务费
                'total_price'=>$getCost['all_cost'],//总费用
                'is_virtual'=>1,
                'pile_id'=>$recordInfo['pile_id'],
                'remark'=>'',
            ];
            return ['code'=>0,'back_data'=>$orderData];
        }
        return ['code'=>1,'back_data'=>[]];
    }

    /**
     * 费用统计
     * @param $recordInfo
     * @return array
     */
    function countCost($recordInfo){
        //获取费率列表
        $costList = $this->backCost();
        $power = 6;
        //开始的时分秒
        $startNumber = strtotime($recordInfo['beg_time']);
        $startHouse = intval(date("H",$startNumber));
        $startMin = intval(date("i",$startNumber));
        $startSecond = intval(date("s",$startNumber));
        //结束的时分秒
        $endNumber = strtotime($recordInfo['end_time']);
        $endHouse = intval(date("H",$endNumber));
        $endMin = intval(date("i",$endNumber));
        $endSecond = intval(date("s",$endNumber));
        $differenceNumber = bcdiv(($endNumber - $startNumber),3600,4);
        $allPower = bcmul($power,$differenceNumber,4);
        //开始和结束同一时间段
        if($startHouse >= $endHouse){
            $startTime = bcdiv(($endNumber - $startNumber),3600,4);
            $startElectricCost = $startTime * $power * $costList[$startHouse]['electric_cost'] ;
            $startServiceCost = $startTime * $power *  $costList[$startHouse]['service_cost'];
            if($startElectricCost < 0) $startElectricCost = 0;
            if($startServiceCost < 0) $startServiceCost = 0;
            $endElectricCost = 0;
            $endServiceCost = 0;
        }else{
            $startTime = bcdiv((3600 -($startMin * 60 + $startSecond)),3600,4);
            $startElectricCost = $startTime * $power * $costList[$startHouse]['electric_cost'];
            $startServiceCost = $startTime * $power * $costList[$startHouse]['service_cost'];
            $endTime = bcdiv(($endMin * 60 + $endSecond),3600,4);
            $endElectricCost = $endTime * $power * $costList[$endHouse]['electric_cost'];
            $endServiceCost = $endTime * $power * $costList[$endHouse]['service_cost'];
        }
        $electricCost = bcadd($startElectricCost,$endElectricCost,4);
        $serviceCost = bcadd($startServiceCost,$endServiceCost,4);
        $status = 1;
        $houseNumber = $startHouse + 1;
        while($status){
            //结束时间大于统计时间
            if($houseNumber < $endHouse){
                $electricCost = $electricCost + $power * $costList[$houseNumber]['electric_cost'];
                $serviceCost = $serviceCost + $power * $costList[$houseNumber]['service_cost'];
                $houseNumber = $houseNumber + 1;
            }else{
                $status = 0;
                break;
            }
        }
        $electricCost = number_format($electricCost,2);
        $serviceCost = number_format($serviceCost,2);
        $allCost = bcadd($electricCost,$serviceCost,2);
        return ['all_power'=>$allPower,'electric_cost'=>$electricCost,'service_cost'=>$serviceCost,'all_cost'=>$allCost];
    }

    /**
     * 获取订单编号
     * @return string
     */
    function getOrderNumber(){
        list($msec, $sec) = explode(' ', microtime());
        $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
        $rand1 = mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
        $rand2 = mt_rand(100, 999);
        $orderSn = 'xn320' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369)).$rand1.$rand2;
        if(strlen($orderSn) > 32){
            $orderSn = substr($orderSn,0,32);
        }else if(strlen($orderSn) < 32){
            $orderSn = str_pad($orderSn,32,'0',STR_PAD_RIGHT);
        }
        return $orderSn;
    }

    /**
     * 获取费率
     * @return array
     */
    function backCost(){
        return [
            0=>['electric_cost'=>0.35,'service_cost'=>0.5],
            1=>['electric_cost'=>0.35,'service_cost'=>0.5],
            2=>['electric_cost'=>0.35,'service_cost'=>0.5],
            3=>['electric_cost'=>0.35,'service_cost'=>0.5],
            4=>['electric_cost'=>0.35,'service_cost'=>0.5],
            5=>['electric_cost'=>0.35,'service_cost'=>0.5],
            6=>['electric_cost'=>0.35,'service_cost'=>0.5],
            7=>['electric_cost'=>0.35,'service_cost'=>0.5],
            8=>['electric_cost'=>0.76,'service_cost'=>0.3],
            9=>['electric_cost'=>0.76,'service_cost'=>0.3],
            10=>['electric_cost'=>1.26,'service_cost'=>0.3],
            11=>['electric_cost'=>1.26,'service_cost'=>0.3],
            12=>['electric_cost'=>0.76,'service_cost'=>0.3],
            13=>['electric_cost'=>0.76,'service_cost'=>0.3],
            14=>['electric_cost'=>1.26,'service_cost'=>0.3],
            15=>['electric_cost'=>1.26,'service_cost'=>0.3],
            16=>['electric_cost'=>1.26,'service_cost'=>0.3],
            17=>['electric_cost'=>1.26,'service_cost'=>0.3],
            18=>['electric_cost'=>1.26,'service_cost'=>0.3],
            19=>['electric_cost'=>0.76,'service_cost'=>0.3],
            20=>['electric_cost'=>0.76,'service_cost'=>0.3],
            21=>['electric_cost'=>0.76,'service_cost'=>0.3],
            22=>['electric_cost'=>0.76,'service_cost'=>0.3],
            23=>['electric_cost'=>0.76,'service_cost'=>0.3],
        ];
    }

    /**
     * 添加之前没有的记录
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function addBeforeOrder(){
        $minId = 0;
        $maxId = 1900;
        dd(1);
        $pileWhere = ['is_status'=>1,'is_virtual'=>1,'is_delete'=>1];
        $pileList = Db::table('jy_charge_ykc_pile')->where($pileWhere)
            ->where('id','>=',$minId)
            ->where('id','<=',$maxId)
            ->order('id','asc')->select()->toArray();
        //dd($pileList);
        $endTime = strtotime(date("Y-m-d")." 23:59:59");
        //$endTime = strtotime("2024-03-17 23:59:59");
        //dd($pileList);
        foreach ($pileList as $key=>$value){
            $addData = mt_rand(2,7);
            //$startTime = strtotime($value['create_time']) + $addData * 24 * 60 *60;
            $startTime = strtotime("2024-02-16 00:00:00");
            while ($startTime <= $endTime){
                $getDay = date("Y-m-d",$startTime);
                $checkData = $this->checkBeforeOrderRecord($value,$getDay);
                //dd($checkData);
                //dump($checkData);
                //没有记录，增加记录
                if($checkData['code'] == 0){
                    $recordResult =  Db::table('jy_charge_ykc_virtual_record')->insert($checkData['back_data']);
                    if(!$recordResult) Log::info('设备id为'.$value['id'].'增加虚拟订单失败');
                }
                $startTime = $startTime + 24 * 60 * 60;
            }
        }
    }

    /**
     * 判断是否指定日期是否已经有虚拟记录
     * @param $value
     * @param $getDay
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function checkBeforeOrderRecord($value,$getDay,$createTime=0){
        /*
        $checkWhere = ['pile_id'=>$value['id'],'date_time'=>$getDay];
        $checkOrderRecord = Db::table('jy_charge_ykc_virtual_record')->where($checkWhere)
            ->where('beg_time','>=',$getDay." 00:00:00")->find();
        */
        $checkWhere = ['charge_terminal'=>$value['dz_name']];
        $checkOrderRecord = Db::table('jy_charge_ykc_order')->where($checkWhere)
            ->where('beg_time','>=',$getDay." 00:00:00")
            ->where('end_time','<=',$getDay." 23:59:59")
            ->find();
        if($checkOrderRecord){
            return ['code'=>1,'msg'=>'有对应的记录','back_data'=>$checkOrderRecord];
        }else{
            $begTimeHouse = mt_rand(0,19);
            $begMinSecond = sprintf("%02s",mt_rand(0,59)).":".sprintf("%02s",mt_rand(0,59));
            $endTimeHouse = $begTimeHouse + mt_rand(4,7);
            if($endTimeHouse > 23) $endTimeHouse = 23;
            $endMinSecond = sprintf("%02s",mt_rand(0,59)).":".sprintf("%02s",mt_rand(0,59));
            if(!$createTime) $createTime = date("Y-m-d H:i:s");
            $backData = [
                'is_status'=>0,
                'dz_name'=>$value['dz_name'],
                'code'=>$value['code'],
                'pile_id'=>$value['id'],
                'beg_time'=>$getDay." ".sprintf("%02s",$begTimeHouse).":".$begMinSecond,
                'end_time'=>$getDay." ".sprintf("%02s",$endTimeHouse).":".$endMinSecond,
                'date_time'=>$getDay,
                'order_id'=>0,
                'create_time'=>$createTime,
                'update_time'=>$createTime,
            ];

            return ['code'=>0,'msg'=>'没有对应的记录','back_data'=>$backData];
        }
    }


    /*************************  添加充电桩  *************************/
    /**
     * 定时器添加虚拟充电桩
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function timeAddVirtualPile(){
        $communityList =  Db::table('jy_community')->where('is_delete',1)->where('open_time','<=',date("Y-m-d H:i:s"))->select();
        $minData = 2;
        $maxData = 3;
        $setTime = 24 * 60 * 60;
        foreach ($communityList as $key=>$value){
            $pileWhere = ['a.community_id'=>$value['id'],'a.is_delete'=>1,'b.is_delete'=>1,'b.is_virtual'=>1];
            $pileCount = Db::table('jy_charge_ykc_community_pile')->alias('a')
                ->leftJoin("jy_charge_ykc_pile b",'a.pile_id = b.id')
                ->where($pileWhere)->count();
            //没有设置上限
            if(!$value['virtual_number'] || $value['virtual_number'] === 0){
                $value['virtual_number'] = mt_rand(120,147);
                Db::table('jy_community')->where('id',$value['id'])->update(['virtual_number'=>$value['virtual_number']]);
            }
            //充电桩数量小于设置的上限
            if($pileCount <= $value['virtual_number']){
                $addStatus = 1;
                //获取最后一条记录
                $pileInfo = Db::table('jy_charge_ykc_community_pile')->alias('a')
                    ->leftJoin("jy_charge_ykc_pile b",'a.pile_id = b.id')
                    ->where($pileWhere)
                    ->where('b.is_virtual',1)
                    ->order('create_time','desc')
                    ->field('a.id,a.community_id,a.pile_id,b.is_virtual,b.create_time')->find();
                //dd($pileInfo);
                if($pileInfo){
                    $getTime = strtotime(date("Y-m-d",strtotime($pileInfo['create_time']))."00:00:00");
                    $nowTime = strtotime(date("Y-m-d",time())."00:00:00");
                    $checkTime = ($nowTime - $getTime) / $setTime;
                    //不到2天
                    if($checkTime < $minData) $addStatus = 0;
                    //2天到3天
                    if($checkTime >= $minData && $checkTime < $maxData){
                        $checkAdd = mt_rand(0,1);
                        if($checkAdd == 0) $addStatus = 0;
                    }
                }
                //添加设备
                if($addStatus == 1){
                    //添加设备数量
                    $addNumber = mt_rand(2,3);
                    for($i = 1;$i<= $addNumber;$i++){
                        $backResult = $this->addVirtualPile($value,$pileCount,date("Y-m-d H:i:s"));
                        $pileCount = $backResult['count_number'];
                    }
                }
            }
        }
    }

    /**
     * 添加之前的充电桩
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function addBeforePile(){
        dd(1);
        $id = 13;
        $communityInfo =  Db::table('jy_community')->where('is_delete',1)->where('id',$id)->find();
        $minData = 2;
        $maxData = 3;
        $setTime = 24 * 60 * 60;
        $pileWhere = ['a.community_id'=>$id,'a.is_delete'=>1,'b.is_delete'=>1,'b.is_virtual'=>1];
        $pileCount = Db::table('jy_charge_ykc_community_pile')->alias('a')
            ->leftJoin("jy_charge_ykc_pile b",'a.pile_id = b.id')
            ->where($pileWhere)->count();
        //没有设置上限
        if(!$communityInfo['virtual_number'] || $communityInfo['virtual_number'] === 0){
            $communityInfo['virtual_number'] = mt_rand(120,147);
            Db::table('jy_community')->where('id',$communityInfo['id'])->update(['virtual_number'=>$communityInfo['virtual_number']]);
        }
        $loopStatus = 1;
        $startDayTime = strtotime($communityInfo['open_time']);
        $pileNumber = $pileCount;
        //充电桩数量小于设置的上限
        while($pileNumber <= $communityInfo['virtual_number'] && $loopStatus){
            if($startDayTime > time()){
                $loopStatus = 0;
                break;
            }
            $addStatus = 1;
            //获取最后一条记录
            $pileInfo = Db::table('jy_charge_ykc_community_pile')->alias('a')
                ->leftJoin("jy_charge_ykc_pile b",'a.pile_id = b.id')
                ->where($pileWhere)
                ->where('b.is_virtual',1)
                ->order('create_time','desc')
                ->field('a.id,a.community_id,a.pile_id,b.is_virtual,b.create_time')->find();
            //dd($pileInfo);
            if($pileInfo){
                $getTime = strtotime(date("Y-m-d",strtotime($pileInfo['create_time']))."00:00:00");
                $nowTime = strtotime(date("Y-m-d",$startDayTime)."00:00:00");
                $checkTime = ($nowTime - $getTime) / $setTime;
                //不到2天
                if($checkTime < $minData) $addStatus = 0;
                //2天到3天
                if($checkTime >= $minData && $checkTime < $maxData){
                    $checkAdd = mt_rand(0,1);
                    if($checkAdd == 0) $addStatus = 0;
                }
            }
            //添加设备
            if($addStatus == 1){
                //添加设备数量
                $addNumber = mt_rand(2,3);
                for($i = 1;$i<= $addNumber;$i++){
                    $backResult = $this->addVirtualPile($communityInfo,$pileCount,date("Y-m-d H:i:s",$startDayTime));
                    $pileCount = $backResult['count_number'];
                    $pileNumber = $pileNumber + 1;
                }
            }
            $startDayTime = $startDayTime + 24 * 60 * 60;
        }
    }

    /**
     * 添加充电桩
     * @param $communityInfo
     * @param $countNumber
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function addVirtualPile($communityInfo,$countNumber,$addTime){
        $getPileData = $this->getPileData($communityInfo,$countNumber,1,$addTime);
        $pileData = $getPileData['pileData'];
        $logInfo = '小区id为：'.$communityInfo['id'].'小区名称：'.$communityInfo['name'];
        if($pileData && !empty($pileData)){
            Db::startTrans();
            $pileId = Db::table('jy_charge_ykc_pile')->insertGetId($pileData);
            if($pileId){
                $relationData = [
                    'community_id'=>$communityInfo['id'],
                    'pile_id'=>$pileId,
                    'is_delete'=>1,
                    'create_time'=>$addTime,
                    'update_time'=>$addTime,
                ];
                $relationResult = Db::table('jy_charge_ykc_community_pile')->insert($relationData);
                if($relationResult){
                    Db::commit();
                }else{
                    Db::rollback();
                    Log::info($logInfo."站点添加新设备失败");
                }
            }else{
                Db::rollback();
                Log::info($logInfo."站点添加新设备失败");
            }
        }else{
            Log::info($logInfo."站点添加设备失败");
        }
        return ['count_number'=>$getPileData['count_number']];
    }

    /**
     * 获取充电桩数据 32 0106 0043331701
     * @param $communityInfo
     * @param $countNumber
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getPileData($communityInfo,$countNumber,$virtual=1,$addTime){
        if(!$communityInfo['ping_ying']) $communityInfo['ping_ying'] = 'CDZMYSZPY';
        $checkStatus = 1;
        $checkNumber = 150;
        $backPileData = [];
        while ($checkStatus <= $checkNumber){
            $countNumber = $countNumber + 1;
            $addNumber = strval($countNumber);
            if(strlen($addNumber) < 4) $addNumber = sprintf("%04s",$addNumber);
            $dzName = $communityInfo['ping_ying'].$addNumber.'-A';
            $setCode =  sprintf("%04s",mt_rand(1,9999));
            $code = "32".time().$setCode;
            $checkPile = Db::table('jy_charge_ykc_pile')->where('dz_name',$dzName)
                ->whereOr('code',$code)->find();
            //存在相同编码
            if($checkPile){
                $checkStatus++;
            }else{
                $backPileData = [
                    'dz_name'=>$dzName,
                    'code'=>$code,
                    'address'=>$countNumber.'号',
                    'is_status'=>1,
                    'is_virtual'=>$virtual,
                    'is_delete'=>1,
                    'create_time'=>$addTime,
                    'update_time'=>$addTime,
                ];
                $checkStatus = 151;
                break;
            }
        }
        return ['count_number'=>$countNumber,'pileData'=>$backPileData];
    }
















}
